﻿//
// Copyright (c) 2024 BPer
//
#ifndef ___BPerWinAudioCaptureHandlee__
#define ___BPerWinAudioCaptureHandlee__
#include <bperaudiodev/BPerAudioCaptureHandle.h>
#include <bperutil/buffer/BPerAudioBuffer.h>
#include <bperavutil/audio/BPerPreProcess.h>

#if BPer_OS_WIN
#include <qedit.h>

#define BPer_Enable_RenderApi 1

#if BPer_Enable_RenderApi
#include "bperWinAudioApiRender.h"
#else
#include "bperAudioPlaySdl.h"
#endif


class BPerWinAudioCaptureHandle: public ISampleGrabberCB,public BPerAudioCaptureHandle
{
public:
    BPerWinAudioCaptureHandle(BPerContext *pcontext);
    virtual ~BPerWinAudioCaptureHandle(void);
    int32_t   readStart;

    STDMETHODIMP_(ULONG) AddRef();
    STDMETHODIMP_(ULONG) Release();
    STDMETHODIMP QueryInterface(REFIID riid, void **ppvObject);
    HRESULT STDMETHODCALLTYPE SampleCB(double Time, IMediaSample *pSample);
    HRESULT STDMETHODCALLTYPE BufferCB(double Time, BYTE *pBuffer, LONG BufferLen);

public:
    BPerPreProcess *m_preProcess;
    void setInAudioBuffer(vector<BPerAudioPlayBuffer*> *pal);
    void setAec(BPerRtcAec *aec);
    void startRender();
    void stopRender();


private:
    uint8_t *m_buf;
    int32_t m_len;

    int32_t m_size;
    int m_asyn;


#if BPer_Enable_RenderApi
    BPerWinAudioApiRender* m_player;
    int m_isStartRender;
#else
    BPerAudioPlaySdl *m_player;
#endif


};
#endif
#endif
